// ----------------------------------------------------------------------
// <author name="Moses Kehengu"/>
// <copyright file="ShortMessage.cs" company="Futures Group International">
//     Copyright statement. All right reserved
// </copyright>
//
// ------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.Common;

namespace GenericTools
{
	public class ShortMessage
	{

		#region Private Variables
		private string index;
		private string status;
		private string sender;
		private string alphabet;
		private string sent;
		private string message;
		#endregion

		#region Public Properties
		public string Index
		{
			get { return index;}
			set { index = value;}
		}
		public string Status
		{
			get { return status;}
			set { status = value;}
		}
		public string Sender
		{
			get { return sender;}
			set { sender = value;}
		}
		public string Alphabet
		{
			get { return alphabet;}
			set { alphabet = value;}
		}
		public string Sent
		{
			get { return sent;}
			set { sent = value;}
		}
		public string Message
		{
			get { return message;}
			set { message = value;}
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Posts the short message message into SendSMSQueue table
		/// </summary>
		/// <returns>True on success otherwise false</returns>
		public bool SendDBSMS()
		{
			DbCommand command = GenericDataAccess.CreateCommand();
            command.CommandType = CommandType.Text;
			command.CommandText = "INSERT INTO [SendSMSQueue] ([SenderNum],[TxtDetails]) VALUES(@SenderNum, @TxtDetails)";

			DbParameter param = command.CreateParameter();
			param.ParameterName = "@SenderNum";
			param.DbType = System.Data.DbType.String;
			param.Size = 50;
			param.Value = this.Sender;
			command.Parameters.Add(param);

			param = command.CreateParameter();
			param.ParameterName = "@TxtDetails";
			param.DbType = System.Data.DbType.String;
			param.Size = 200;
			param.Value = this.Message;
			command.Parameters.Add(param);

			return (GenericDataAccess.ExecuteNonQuery(command) > 0);
		}

        /// <summary>
        /// Posts the short message message into SendSMSQueue table
        /// </summary>
        /// <param name="message">Short message description object</param>
        /// <returns>True on success otherwise false</returns>
        public static bool SendDBSMS(ShortMessage message)
        {
            DbCommand command = GenericDataAccess.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "INSERT INTO [SendSMSQueue] ([SenderNum],[TxtDetails]) VALUES(@SenderNum, @TxtDetails)";

            DbParameter param = command.CreateParameter();
            param.ParameterName = "@SenderNum";
            param.DbType = System.Data.DbType.String;
            param.Size = 50;
            param.Value = message.Sender;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@TxtDetails";
            param.DbType = System.Data.DbType.String;
            param.Size = 200;
            param.Value = message.Message;
            command.Parameters.Add(param);

            return (GenericDataAccess.ExecuteNonQuery(command) > 0);
        }

        /// <summary>
        /// Posts the short message message from number into SendSMSQueue table
        /// </summary>
        /// <param name="number">Phone number</param>
        /// <param name="message">Message</param>
        /// <returns>True on success otherwise false</returns>
        public static bool SendDBSMS(string number, string message)
        {
            DbCommand command = GenericDataAccess.CreateCommand();
            command.CommandType = CommandType.Text;
            command.CommandText = "INSERT INTO [SendSMSQueue] ([SenderNum],[TxtDetails]) VALUES(@SenderNum, @TxtDetails)";

            DbParameter param = command.CreateParameter();
            param.ParameterName = "@SenderNum";
            param.DbType = System.Data.DbType.String;
            param.Size = 50;
            param.Value = number;
            command.Parameters.Add(param);

            param = command.CreateParameter();
            param.ParameterName = "@TxtDetails";
            param.DbType = System.Data.DbType.String;
            param.Size = 200;
            param.Value = message;
            command.Parameters.Add(param);

            return (GenericDataAccess.ExecuteNonQuery(command) > 0);
        }
		#endregion
	}

    public class ShortMessageCollection : List<ShortMessage> { }
}
